import { GBox } from "../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { GButton } from "../../../../com/mui/controls/GButton";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { NationalTreasureInfo } from "../../model/NationalTreasureInfo";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { Game } from "../../Game";
import { ECamp } from "../../../../Message/Public/ECamp";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ETaskGroup } from "../../../../Message/Game/ETaskGroup";
import { ETaskStatus } from "../../../../Message/Game/ETaskStatus";
//class NationalTreasureOptPanel
    
    export  class NationalTreasureOptPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._campPassBtns = [];
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            var loc2=null;
            this._body = new GBox();
            this._body.direction = GBoxDirection.HORIZONTAL;
            this._body.horizontalGap = 5;
            addChild(this._body);
            var loc1=0;
            while (loc1 < 3) 
            {
                loc2 = new GButton();
                loc2.styleName = "ButtonSpecial";
                loc2.textField.filters = [FilterConst.nameGlowFilter];
                loc2.setSize(75, 25);
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onPassBtnClickHandler);
                this._campPassBtns.push(loc2);
                ++loc1;
            }
            return;
        }

        /* internal  */onCheckInBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureJoinReq));
            return;
        }

        /* internal  */onPassBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasurePassNPC, int(loc1.name)));
            return;
        }

        /* internal  */onHandOutBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureHandOutReq));
            return;
        }

        public updateData(arg1: NationalTreasureInfo): void
        {
            var loc1=false;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=null;
            var loc6=0;
            this.dispose();
            this._info = arg1;
            if (arg1.hasCheckIn) 
            {
                loc1 = true;
                if (arg1.isHandOutItemTime) 
                {
                    loc1 = true;
                }
                else 
                {
                    loc1 = false;
                }
                if (Cache.instance.dialog.npcInfo && !Cache.instance.scene.isNationalSeizeNPC(Cache.instance.dialog.npcInfo.tnpc.npcId)) 
                {
                    if (!this._handOutBtn) 
                    {
                        this._handOutBtn = new GButton();
                        this._handOutBtn.styleName = "ButtonSpecial";
                        this._handOutBtn.label = Language.getString(27023);
                        this._handOutBtn.setSize(75, 25);
                        this._handOutBtn.textField.filters = [FilterConst.nameGlowFilter];
                        this._handOutBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onHandOutBtnClickHandler);
                    }
                    this._handOutBtn.enabled = loc1;
                    this._body.addChild(this._handOutBtn);
                }
                loc3 = this._info.openCamp.length;
                loc6 = -1;
                while (loc2 < loc3) 
                {
                    loc4 = this._info.openCamp[loc2];
                    (loc5 = this._campPassBtns[loc2]).name = loc4.toString();
                    if (loc4 != Cache.instance.role.entityInfo.camp) 
                    {
                        if (Game.sceneInfo.sMapDefine.campType.__value != ECamp._ECampNeutral) 
                        {
                            if (Game.sceneInfo.sMapDefine.campType.__value != Cache.instance.role.entityInfo.camp) 
                            {
                                ++loc2;
                                continue;
                            }
                            else 
                            {
                                loc5.label = GameDefConfig.instance.getECamp(loc4) + Language.getString(27005);
                                this._body.addChild(loc5);
                            }
                        }
                        else 
                        {
                            loc5.label = GameDefConfig.instance.getECamp(loc4) + Language.getString(27005);
                            this._body.addChild(loc5);
                        }
                    }
                    else if (loc4 != Game.sceneInfo.sMapDefine.campType.__value) 
                    {
                        loc5.label = Cache.instance.role.getCampName() + Language.getString(27006);
                        loc6 = loc2;
                    }
                    loc5.enabled = arg1.checkInStart;
                    ++loc2;
                }
                if (Game.sceneInfo.sMapDefine.campType.__value != ECamp._ECampNeutral) 
                {
                    if (!this._camp4PassBtn) 
                    {
                        this._camp4PassBtn = new GButton();
                        this._camp4PassBtn.styleName = "ButtonSpecial";
                        this._camp4PassBtn.textField.filters = [FilterConst.nameGlowFilter];
                        this._camp4PassBtn.setSize(75, 25);
                        this._camp4PassBtn.name = "4";
                        this._camp4PassBtn.label = Cache.instance.scene.getSceneInfoByCamp(4, 1).sMapDefine.name;
                        this._camp4PassBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onPassBtnClickHandler);
                    }
                    this._camp4PassBtn.enabled = loc1;
                    this._body.addChild(this._camp4PassBtn);
                }
                if (loc6 != -1) 
                {
                    loc5 = this._campPassBtns[loc6];
                    this._body.addChild(loc5);
                }
            }
            else 
            {
                if (!this._checkInBtn) 
                {
                    this._checkInBtn = new GButton();
                    this._checkInBtn.setSize(75, 25);
                    this._checkInBtn.styleName = "ButtonSpecial";
                    this._checkInBtn.label = Language.getString(27022);
                    this._checkInBtn.textField.filters = [FilterConst.nameGlowFilter];
                    this._checkInBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCheckInBtnClickHandler);
                }
                this._body.addChild(this._checkInBtn);
                this._checkInBtn.enabled = arg1.checkInStart;
                if (this._checkInBtn.enabled) 
                {
                    this._checkInBtn.label = Language.getString(27022);
                }
                else 
                {
                    this._checkInBtn.label = Language.getString(27024);
                }
                if (this._checkInBtn.enabled && !(Game.sceneInfo.sMapDefine.campType.__value == ECamp._ECampNeutral) && Cache.instance.task.hasTaskByGroup(ETaskGroup._ETaskGroupCampTreasure, true, ETaskStatus._ETaskStatusHadCompleted) && !Cache.instance.task.hasTaskByGroup(ETaskGroup._ETaskGroupTreasure, true, ETaskStatus._ETaskStatusHadCompleted)) 
                {
                    if (!this._camp4PassBtn) 
                    {
                        this._camp4PassBtn = new GButton();
                        this._camp4PassBtn.styleName = "ButtonSpecial";
                        this._camp4PassBtn.textField.filters = [FilterConst.nameGlowFilter];
                        this._camp4PassBtn.setSize(75, 25);
                        this._camp4PassBtn.name = "4";
                        this._camp4PassBtn.label = Cache.instance.scene.getSceneInfoByCamp(4, 1).sMapDefine.name;
                        this._camp4PassBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onPassBtnClickHandler);
                    }
                    this._body.addChild(this._camp4PassBtn);
                }
            }
            if (this._body.numChildren != 4) 
            {
                if (this._body.numChildren != 3) 
                {
                    if (this._body.numChildren != 2) 
                    {
                        this._body.horizontalGap = 40;
                    }
                    else 
                    {
                        this._body.horizontalGap = 30;
                    }
                }
                else 
                {
                    this._body.horizontalGap = 10;
                }
            }
            else 
            {
                this._body.horizontalGap = 2;
            }
            this._body.invalidate();
            this._body.x = (this.width - this._body.numChildren * 75 - (this._body.numChildren + 1) * this._body.horizontalGap) / 2;
            return;
        }

        public dispose(): void
        {
            this._info = null;
            while (this._body.numChildren > 0) 
            {
                this._body.removeChildAt(0);
            }
            return;
        }

        public /* override */ get width(): number
        {
            return 314;
        }

        public /* override */ get height(): number
        {
            return 25;
        }

        protected /* var */_body: GBox;

        protected /* var */_info: NationalTreasureInfo;

        protected /* var */_checkInBtn: GButton;

        protected /* var */_handOutBtn: GButton;

        protected /* var */_campPassBtns: Array<any>;

        protected /* var */_camp4PassBtn: GButton;
    }
